package com.tengju.activity.infrastructure.repository;

import com.tengju.activity.domain.model.activity.ActivityId;
import com.tengju.activity.domain.model.activity.ActivitySignUp;
import com.tengju.activity.domain.model.activity.ActivitySignUpRepository;
import com.tengju.activity.domain.model.user.UserIdCode;
import com.tengju.activity.infrastructure.persistence.mybatis.dataobject.ActivitySignUpDO;
import com.tengju.activity.infrastructure.persistence.mybatis.mapper.ActivitySignUpMapper;
import com.tengju.activity.infrastructure.repository.convert.ActivitySignUpConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Repository
public class ActivitySignUpRepositoryImpl implements ActivitySignUpRepository {

    @Resource
    private ActivitySignUpMapper activitySignUpMapper;

    @Override
    public void signUp(ActivitySignUp activitySignUp) {
        ActivitySignUpDO activitySignUpDO = ActivitySignUpConvert.convertToDo(activitySignUp);
        activitySignUpDO.setCreateTime(LocalDateTime.now());
        activitySignUpDO.setUpdateTime(LocalDateTime.now());
        activitySignUpMapper.signUp(activitySignUpDO);
    }

    @Override
    public Integer countByActivityId(ActivityId activityId) {
        return activitySignUpMapper.countByActivityId(activityId.getValue());
    }

    @Override
    public Boolean hasSignUp(UserIdCode idCode, ActivityId activityId) {
        return activitySignUpMapper.hasSignUp(idCode.getValue(),activityId.getValue()) != null;
    }
}
